﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
    ManageDatabase data;
    List<Serie> series;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (data == null)
        {
            data = new ManageDatabase();
        }
        if (!IsPostBack)
        {
            Initialize();
            RegisterHyperLink.NavigateUrl = "Account/Register.aspx";
        }
    }

    private void Initialize()
    {

        series = data.GetSeriesPreviewTop3();

        foreach (Serie item in series)
        {

            Panel SeriePanel = new Panel();
            HtmlGenericControl FieldSet = new HtmlGenericControl("fieldset");
            Table SerieTable = new Table();
            TableRow SerieRow = new TableRow();
            TableCell SerieCellLeft = new TableCell();
            TableCell SerieCellRight = new TableCell();
            Table InfoTable = new Table();
            TableRow Info1Row = new TableRow();
            TableCell Info1Cell = new TableCell();
            TableRow Info2Row = new TableRow();
            TableCell Info2Cell = new TableCell();
            TableRow Info3Row = new TableRow();
            TableCell Info3Cell = new TableCell();
            TableRow Info4Row = new TableRow();
            TableCell Info4Cell = new TableCell();
            Image ThumbImage = new Image();
            HyperLink TitleHun = new HyperLink();
            Label Status = new Label();
            Label TitleOrig = new Label();
            Label ReleaseDate = new Label();
            Label Description = new Label();

            SeriePanel.ID = "SeriePanel" + item.id.ToString();
            SerieTable.ID = "SerieTable" + item.id.ToString();
            SerieRow.ID = "SerieRow" + item.id.ToString();
            SerieCellLeft.ID = "SerieCellLeft" + item.id.ToString();
            SerieCellRight.ID = "SerieCellRight" + item.id.ToString();
            ThumbImage.ID = "ThumbImage" + item.id.ToString();
            TitleHun.ID = "TitleHun" + item.id.ToString();
            Status.ID = "Status" + item.id.ToString();
            TitleOrig.ID = "TitleOrig" + item.id.ToString();
            ReleaseDate.ID = "ReleaseDate" + item.id.ToString();
            Description.ID = "Description" + item.id.ToString();

            SeriePanel.CssClass = "previewPanel";
            TitleHun.CssClass = "previewTitleHun";
            Status.CssClass = "previewStatus";
            TitleOrig.CssClass = "previewTitleOrig";
            ReleaseDate.CssClass = "previewReleaseDate";
            Description.CssClass = "previewDescription";

            if (item.imgUrl != "")
                ThumbImage.ImageUrl = "~/Pic/" + item.imgUrl;
            else
                ThumbImage.ImageUrl = "~/images/nopic.png";
            ThumbImage.Width = 150;
            ThumbImage.Height = 150;
            TitleHun.Text = item.titleHun;
            TitleHun.NavigateUrl = "Seasons.aspx?sorozat=" + item.id.ToString();
            TitleOrig.Text = item.titleOrig;
            ReleaseDate.Text = String.Format("{0:yyyy.MM.dd}", item.releaseDate);
            if (item.description.Length > 500)
                Description.Text = item.description.Substring(0, 500) + "...";
            else
                Description.Text = item.description;

            Info1Cell.Controls.Add(TitleHun);
            Info2Cell.Controls.Add(TitleOrig);
            if (item.status != 1)
            {
                Status.Text = "   (Nem engedélyezett)";
                Info2Cell.Controls.Add(Status);
            }
            Info3Cell.Controls.Add(ReleaseDate);
            Info4Cell.Controls.Add(Description);

            Info1Row.Controls.Add(Info1Cell);
            Info2Row.Controls.Add(Info2Cell);
            Info3Row.Controls.Add(Info3Cell);
            Info4Row.Controls.Add(Info4Cell);

            InfoTable.Controls.Add(Info1Row);
            InfoTable.Controls.Add(Info2Row);
            InfoTable.Controls.Add(Info3Row);
            InfoTable.Controls.Add(Info4Row);

            SerieCellLeft.Controls.Add(ThumbImage);
            SerieCellRight.Controls.Add(InfoTable);

            SerieRow.Controls.Add(SerieCellLeft);
            SerieRow.Controls.Add(SerieCellRight);
            SerieTable.Controls.Add(SerieRow);
            FieldSet.Controls.Add(SerieTable);

            SeriesPanel.Controls.Add(FieldSet);
        }

    }
}
